package com.sdyeda.readiot.fx;

import java.io.IOException;

import com.sdyeda.readiot.ReadIotApplication;
import com.sdyeda.readiot.data.SetSave;

import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class SetSaveDetailWindow {

	private SetSaveDetailController setSaveDetailController;

	public SetSaveDetailController getSetSaveDetailController() {
		return setSaveDetailController;
	}

	public void setSetSaveDetailController(SetSaveDetailController setSaveDetailController) {
		this.setSaveDetailController = setSaveDetailController;
	}

	public SetSaveDetailWindow(Stage stage, Stage parentstage, SetSave save) {
		FXMLLoader loader = new FXMLLoader(getClass().getResource("SetSaveDetail.fxml"));
		loader.setControllerFactory(ReadIotApplication.springContext::getBean);
		try {
			stage.setScene(new Scene(loader.load()));

			stage.setTitle("尾矿库自动数据采集系统--" + (save == null ? "添加" : "修改"));
			stage.getIcons().add(new Image(MainWindow.class.getResourceAsStream("/logo.png")));
			stage.initOwner(parentstage);
			stage.initModality(Modality.WINDOW_MODAL);
			stage.setResizable(false);
			
			setSetSaveDetailController(loader.getController());
			setSaveDetailController.setStage(stage);
			setSaveDetailController.setSetSave(save);
			
			stage.setOnShown(event ->{
				setSaveDetailController.LoadData();
			});

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
